<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="base" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备管理</title>
	<link href="${base}/assets/css/public.css" rel="stylesheet">
	<link href="${base}/assets/css/jquery.searchableSelect.css" rel="stylesheet">
	<script src="${base}/assets/js/jquery.min.js"></script>
	<script src="${base}/assets/js/jquery.searchableSelect.js"></script>
	<link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/gray/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/icon.css" />
	<script type="text/javascript" src="${base}/assets/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${base}/assets/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<div class="top">
   <c:import url="../commons/top.jsp"/>
</div>
<div class="wrap">
  <div class="side">
   	<c:import url="../commons/sidebar.jsp"/>
  </div>
  <div class="cont">
    <div class="bread">
      	<span>设备管理</span><span>&nbsp;&gt;&nbsp;</span><span>修改设备</span>
      	<div class="exl">
        </div>
        <div class="excel-add">
      		<a class="add" style="float: right;margin-right: 30px;" href="javascript:void(0)" onclick="fahui()">返回</a>
        </div>
      <div class="clear"></div>
      <script type="text/javascript">
		function fahui(){
			window.location.href ="${base}/back/devicdetail.do?id=${dd.id}"; 
		}
      </script>
    </div>
<form method="post" action="${base}/back/userAdd.do" id="donaForm">
	<input type="hidden"  name="id" value="${dd.id}"/>
	<input type="hidden"  name="status" value="${dd.status}"/>
	<input type="hidden" id="fcidt" name="fcidt" value="${dd.fcid}"/>
	<input type="hidden"  id="dcidt" name="dcidt" value="${dd.dcid}"/>
    <div class="form-group">
        <label>所属分类:</label>
        <div class="group-add" style="position:relative;z-index:10">
            <select  id="cid" name="cid">
            	<option value=""></option>
	           	<c:forEach items="${maxc}" var="m">
	            	<option value="${m.id}" <c:if test="${dd.cid==m.id}">selected="selected"</c:if>>${m.name}</option>
	            </c:forEach>
           	</select>
        </div>
      <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>功能分类:</label>
        <div class="group-add" style="position:relative;z-index:9" id="fciddiv">
          <select  id="fcid" name="fcid" >
              <option value=""/></option>
          </select>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>设备分类:</label>
        <div class="group-add" style="position:relative;z-index:8" id="dciddiv">
          <select id="dcid" name="dcid" >
              <option value=""></option>
          </select>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>品牌:</label>
        <div class="group-add">
        	<input name="brand" class="easyui-validatebox" data-options="required:true" placeholder="" value="${ddv.brand}"/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>旧编号:</label>
        <div class="group-add">
        	<input name="oldno" value="${ddv.oldno}" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>编号:</label>
        <div class="group-add">
        <input id="no" name="no" value="${ddv.no}" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>型号:</label>
        <div class="group-add">
        	<input name="xhno" value="${ddv.xhno}" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>出厂编号:</label>
        <div class="group-add">
        	<input name="ccno" value="${ddv.ccno}" class="easyui-validatebox" data-options="required:true"/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>投产时间:</label>
        <div class="group-add">
        	<input name="tcrq" value="${ddv.tcrq}" style="height:34px" placeholder="" class="easyui-datetimebox" data-options="required:true"/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>折旧年限:</label>
        <div class="group-add">
        	<input name="zjnx" value="${ddv.zjnx}" style="height:34px" class="easyui-numberbox" data-options="required:true,min:0,max:100,suffix:'年'"  placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>采购价格:</label>
        <div class="group-add">
        	<input name="cgjg" value="${ddv.cgjg}" style="height:34px" class="easyui-numberbox" data-options="required:true,min:0,precision:2,suffix:'元'"  placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>当前位置:</label>
        <div class="group-add">
          <input name="wid" disabled style="height:34px" class="easyui-validatebox" data-options="required:true" placeholder="" value ="${ddv.whname}" />
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>备注：</label>
        <div class="group-add">
        	<textarea name="remark" class="easyui-validatebox" style="width:60%" rows="3" cols="9">${ddv.remark}</textarea>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-actions">
        <a class="btn" style="background-color:#337ab7; color:#fff" onclick="submitDona()">提交</a>
        <button type="reset" class="btn">重置</button>
        <div class="clear"></div>
    </div>
</form>
  </div>
</div>
<div class="clear"></div>
</body>
</html>
<script type="text/javascript">

 $(function(){

	 $('#cid').searchableSelect({  
	        afterSelectItem: function(){  
	           var fsv= this.holder.data("value");
	            if(fsv!=null && fsv!=''){
	            	$.ajax({
						url: '${base}/back/searchmidc.do?pid='+fsv,
						async:false,
						dataType:"json",
						type:"post",
						success:function (data){
							$('#fciddiv').html("");
							var list = data.midc;
							if(list.length>0){
								var sel = '<select id="fcid" name="fcid" ><option value=""></option>'
								var fs = $('#fcidt').val();
								$.each(list,function(index,item){
									 sel +='<option value=" '+
											item.id + '"' ;
									 if(item.id==fs){
										 sel+='selected="selected">'+item.name+'</option>';
									 }else{
										 sel+='">'+item.name+'</option>';
										}
								});
								sel += '</select>';
								$('#fciddiv').append(sel);
								fcidcaozuo();
								//$('#fcid').show();
							}else{
								var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
								$('#fciddiv').append(sel);
								$('#fcid').searchableSelect();
								//$('#fcid').show();
							} 	
						},
					});
	            }
	        }	 
	    });
		function fcidcaozuo(){
			$('#fcid').searchableSelect({  
		        afterSelectItem: function(){  
		            var fsv= this.holder.data("value");
		            if(fsv!=null && fsv!=''){
		             	$.ajax({
		 					url: '${base}/back/searchmidc.do?pid='+fsv,
		 					async:false,
		 					dataType:"json",
		 					type:"post",
		 					success:function (data){
		 						$('#dciddiv').html("");
		 						var list = data.midc;
		 						if(list.length>0){
									var sel = '<select id="dcid" name="dcid" ><option value=""></option>'
									var fs = $('#dcidt').val();
									$.each(list,function(index,item){
										 sel +='<option value=" '+
												item.id + '"' ;
										 if(item.id==fs){
											 sel+='selected="selected">'+item.name+'</option>';
										 }else{
											 sel+='">'+item.name+'</option>';
											}
									});
									sel += '</select>';
									$('#dciddiv').append(sel);
									$('#dcid').searchableSelect();
								}else{
									var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
									$('#dciddiv').append(sel);
									$('#dcid').searchableSelect();
								} 
							}, 
		 				});
		             }	
		         }  
		     });
		}
	$("#no").change(function() { 
		console.log("1111111111")
				var uacc = $.trim($("#no").val());
				   $.ajax({
			        type: "POST",
			        dataType: "json", // 数据格式:JSON
			        url: '${base}/back/nocheck.do?no='+uacc,
			       // data: postData,
			        success: function (data) {
			     	   if(data.ok == 'ok'){ 
			     	   }else{
			     		   alert("编号已存在！！")
			     		   return;
			     	   }
			        }
			       
			    });
		});
}); 

   function submitDona(){
	 
	   if(!$('#donaForm').form('validate')){
           return false;
       }
	   var postData = $('#donaForm').serialize();
       $.ajax({
           type: "POST",
           url: '${base}/back/devicemodsub.do',
           data: postData,
           success: function (data) {
        	   var mymessage=window.confirm('修改成功！是否返回');  
			   if(mymessage==true){  
			   		window.location.href = "${base}/back/devicdetail.do?id=${dd.id}"; 
			   }else if(mymessage==false){  
			   		 return; 
			   }
           }
       });
   }
  

</script>

